package cn.com.zpark.servlet_response;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @PackageName: cn.com.zpark.servlet_response
 * @ClassName: ResponseDemo07
 * @Description:
 * @author: RZS
 * @date: 2021/11/14  9:27
 */
@WebServlet("/rd7.jsp")
public class ResponseDemo07 extends HttpServlet {

    int num = 5;

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter w = resp.getWriter();

        if(num >= 0){
            // 设置页面定时刷新，间隔1秒一次,设置响应头字段（refresh）实现页面的定时跳转
            resp.setHeader("refresh", "1");
            w.write("<center><h1>" +num+
                    "秒之后跳转回登录页面</h1></center>");
            num--;

        }else{
            // 设置跳转页面，设置3秒钟跳转
            //resp.setHeader("refresh", "3;url=/Servlet/view/index.html");
            resp.sendRedirect(this.getServletContext().getContextPath()+"/view/index.html");
        }

    }
}
